package itsm.isperp.module.utils;

import itsm.isperp.framework.core.context.ContextHolder;

import org.joda.time.DateTime;
import org.joda.time.LocalTime;

/**
 * 
 * 
 * 
 * @author lizx
 * @date 2015-1-10
 * @since 1.0
 * 
 */
public class WechatConfigUtils {

	/**
	 * 当前时间是否为微信服务台工作时间
	 * 
	 * @return 是否为微信服务台工作时间
	 */
	public static boolean isWechatWorktime() {

		DateTime dt = DateTime.now();

		int dayOfWeek = dt.dayOfWeek().get();
		String wechatWorkWeek = ContextHolder.getConfigByKey("wechatWorkWeek"
				+ dayOfWeek);

		// 工作日
		if ("1".equals(wechatWorkWeek)) {

			LocalTime wechatWorkAmBeginTime = LocalTime.parse(ContextHolder
					.getConfigByKey("wechatMpWorkAmBegin"));
			LocalTime wechatWorkAmEndTime = LocalTime.parse(ContextHolder
					.getConfigByKey("wechatMpWorkAmEnd"));
			LocalTime wechatWorkPmBeginTime = LocalTime.parse(ContextHolder
					.getConfigByKey("wechatMpWorkPmBegin"));
			LocalTime wechatWorkPmEndTime = LocalTime.parse(ContextHolder
					.getConfigByKey("wechatMpWorkPmEnd"));

			// 当前钟点
			LocalTime nowTime = dt.toLocalTime();
			// 是否为钟点范围
			if (nowTime.isAfter(wechatWorkAmBeginTime)
					&& nowTime.isBefore(wechatWorkAmEndTime)
					|| (nowTime.isAfter(wechatWorkPmBeginTime) && nowTime
							.isBefore(wechatWorkPmEndTime))) {
				return true;
			}
		}

		return false;
	}
}
